
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  //入口文件
  entry: path.join(__dirname, './src', 'index.js'),
  
  //输出文件
  output: {
    filename: 'index.js',
    path: path.resolve(__dirname, './dist')
  },
  
  //模块
  module: {
    rules: [
      {
        test: /\.css$/,
        include: [
          path.resolve(__dirname, './src')
        ],
        exclude: [
          path.resolve(__dirname, './node_modules'),
          path.resolve(__dirname, './bower_components')
        ],
        loader: 'style-loader!css-loader'
      },
      {
        test: /\.(scss|sass)$/,
        include: [
          path.resolve(__dirname, './src')
        ],
        exclude: [
          path.resolve(__dirname, './node_modules'),
          path.resolve(__dirname, './bower_components')
        ],
        loader: 'style-loader!css-loader!sass-loader'
      },
      {
        test: /\.js?$/,
        include: [
          path.resolve(__dirname, './src')
        ],
        exclude: [
          path.resolve(__dirname, './node_modules'),
          path.resolve(__dirname, './bower_components')
        ],
        loader: 'babel-loader',
        query: {
          presets: [
            'env',
            'stage-0'
          ]
        }
      },
      {
        test: /\.vue$/,
        include: [
          path.resolve(__dirname, './src')
        ],
        exclude: [
          path.resolve(__dirname, './node_modules'),
          path.resolve(__dirname, './bower_components')
        ],
        loader: 'vue-loader'
      },
      {
        test: /\.pug$/,
        include: [
          path.resolve(__dirname, './src')
        ],
        exclude: [
          path.resolve(__dirname, './node_modules'),
          path.resolve(__dirname, './bower_components')
        ],
        loader: 'pug-loader'
      }
    ]
  },
  
  resolve: {
    extensions: ['.json', '.js', '.css'],
    alias: {
      'vue': 'vue/dist/vue.js'
    }
  },
  
  //生成映射文件
  //devtool: 'source-map',
  
  devServer: {
    //这个有什么作用还要详细了解
    //publicPath: path.join('/dist/'),

    //内容目录路径
    contentBase: path.join('/dist/'),
    //服务器端口
    port: 1111,
    //文件修改自动刷新浏览器
    inline: true
  },

  //插件
  plugins: [
    //html整合插件，负责生成包含目标js文件的html文件
    new HtmlWebpackPlugin({
        template: "./src/index.html",
        filename: "index.html",
    })
  ]
};